package com.itheima.ThreadTest.restaurant;

import java.util.ArrayList;

public class Desk {
    ArrayList<String> list = new ArrayList<>();

    public synchronized void put() throws InterruptedException {
        String name = Thread.currentThread().getName();
        if(list.isEmpty()) {
            list.add(name);
            System.out.println(name);
        }
        Thread.sleep(2000);
        this.notifyAll();
        this.wait();
    }

    public synchronized void get() throws InterruptedException {
        String name = Thread.currentThread().getName();
        if(!list.isEmpty()) {
            list.clear();
            System.out.println(name);
        }
        Thread.sleep(2000);
        this.notifyAll();
        this.wait();
    }
}
